import 'package:flutter/material.dart';
import 'package:flutter_app_05/action/states/data_manager.dart';
import 'package:flutter_app_05/data/model.dart';
import 'package:flutter_app_05/http/nets.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_app_05/widget/stateful_widget_extends.dart';
import 'package:flutter_app_05/widget/sdk_extends.dart';

import 'more_dtl.dart';

class More02Page extends StatefulWidget {
  @override
  MorePage02PageState createState() => new MorePage02PageState();
}

class MorePage02PageState extends State<More02Page> {
  List<InfoData> _list;
int page=1;
  @override
  Widget build(BuildContext context) {
    return _list == null
        ? Container(
            child: Center(
              child: Text("加载中..."),
            ),
          )
        : new RefreshIndicator(
      onRefresh: _onRefresh,

      child: ListView.separated(itemBuilder: (context,index){
        return  infoModel(context, _list[index]);
      }, separatorBuilder: (context,index){
        return Divider();
      }, itemCount: _list.length,

      ),
    );

    ListView(
            scrollDirection: Axis.vertical,
            children: [
              ..._list.map((e) => infoModel(context, e)),
            ],
          );
  }
  Future<void> _onRefresh() async {
    page=1;
    var a = await DataManager.getOther(p: {"page":"1", "perPage": "1"})
        .then((value) {
      _list.clear();

      _list=value.data;
      setState(() {});
    });

  }
  Widget infoModel(BuildContext context, InfoData infoData) {
    return GestureDetector(
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            margin: EdgeInsets.only(left: 10.0, top: 10.0),
            height: 80.0,
            width: 80.0,
            decoration: BoxDecoration(
              color: MyTheme(context).getColor('white'),
              border: Border.all(
                color: Colors.transparent,
                width: 2,
              ),
              borderRadius: BorderRadius.circular(12),
            ),
            child: (RequestPaths.urlBase + "/" + infoData.link)
                .getImage(width: 40.0, height: 40.0),
          ),
          SizedBox(
            width: 10.0,
          ),
          Expanded(
            child: Container(
              margin: EdgeInsets.only(right: 10.0, top: 10.0),
              height: 80.0,
              decoration: BoxDecoration(
                color: MyTheme(context).getColor('white'),
                border: Border.all(
                  color: Colors.transparent,
                  width: 2,
                ),
                borderRadius: BorderRadius.circular(12),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    height: 8.0,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10.0),
                    child: Text(
                      infoData.title,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(
                          fontSize: 18.0,
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ),
                  SizedBox(
                    height: 14.0,
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 10.0),
                    child: Text(
                      infoData.introduce,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(fontSize: 12.0, color: Colors.grey),
                    ),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
      onTap: () {
        this.push(MoreDetilPage(
          img: infoData.link,
        ));
      },
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _initInfo();
  }

  Future<bool> _initInfo() async {
    var a = await DataManager.getOther(p: {"page": "1", "perPage": "1"})
        .then((value) {
      _list = value.data;
      setState(() {});
    });
  }
}
